package gui;

public class NetConfPane extends javax.swing.JPanel {
	private static final long serialVersionUID = 1L;

	private javax.swing.JTextField LPortField = null;
	private javax.swing.JTextField RPortField = null;
	private javax.swing.JTextField RIpField = null;

	private int lport;
	private int rport;
	private java.lang.String rip;

	public NetConfPane(int lport, int rport, java.lang.String rip){
		super();
		this.init(lport, rport, rip);
	}

	private void init(int lport, int rport, java.lang.String rip){
		this.lport = lport;
		this.rport = rport;
		this.rip = rip;
		this.setBorder(new javax.swing.border.EmptyBorder(10, 0, 10, 0));
		this.setLayout(new java.awt.GridLayout(3, 1, 0, 10));
		this.add(this.getLocalPortPane());
		this.add(this.getRemoteIpPane());
		this.add(this.getRemotePortPane());
	}

	private javax.swing.JPanel getLocalPortPane(){
		javax.swing.JPanel jp = new javax.swing.JPanel();
		jp.setLayout(new java.awt.BorderLayout());
		javax.swing.JLabel l = new javax.swing.JLabel("Local Port: ");
		l.setHorizontalAlignment(javax.swing.JLabel.RIGHT);
		jp.add(l, java.awt.BorderLayout.CENTER);
		this.LPortField = new javax.swing.JTextField(10);
		this.LPortField.setText("" + this.lport);
		jp.add(this.LPortField, java.awt.BorderLayout.EAST);
		return(jp);
	}
	private javax.swing.JPanel getRemotePortPane(){
		javax.swing.JPanel jp = new javax.swing.JPanel();
		jp.setLayout(new java.awt.BorderLayout());
		javax.swing.JLabel l = new javax.swing.JLabel("Remote Port: ");
		l.setHorizontalAlignment(javax.swing.JLabel.RIGHT);
		jp.add(l, java.awt.BorderLayout.CENTER);
		this.RPortField = new javax.swing.JTextField(10);
		this.RPortField.setText("" + this.rport);
		jp.add(this.RPortField, java.awt.BorderLayout.EAST);
		return(jp);
	}
	private javax.swing.JPanel getRemoteIpPane(){
		javax.swing.JPanel jp = new javax.swing.JPanel();
		jp.setLayout(new java.awt.BorderLayout());
		javax.swing.JLabel l = new javax.swing.JLabel("Remote IP: ");
		l.setHorizontalAlignment(javax.swing.JLabel.RIGHT);
		jp.add(l, java.awt.BorderLayout.CENTER);
		this.RIpField = new javax.swing.JTextField(10);
		this.RIpField.setText(this.rip);
		jp.add(this.RIpField, java.awt.BorderLayout.EAST);
		return(jp);
	}

	public boolean checkSanity(){
		java.lang.Integer auxLPort, auxRPort;
		java.lang.String ip = this.RIpField.getText();
		try{
			auxLPort = java.lang.Integer.decode(this.LPortField.getText());
			auxRPort = java.lang.Integer.decode(this.RPortField.getText());
			this.rip = ip;
			this.lport = auxLPort.intValue();
			this.rport = auxRPort.intValue();
		}catch(java.lang.NumberFormatException ex){
			return(false);
		}
		return(true);
	}
	public int getLPort(){
		return(this.lport);
	}
	public int getRPort(){
		return(this.rport);
	}
	public java.lang.String getRIp(){
		return(this.rip);
	}
}
